<!doctype html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title th:text="${platformName}+'任务调度平台'"></title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="icon" th:href="@{../static/layui/images/logo.png}">
    <link rel="stylesheet" th:href="@{../static/layui/css/font.css}">
    <link rel="stylesheet" th:href="@{../static/layui/css/login.css}">
    <link rel="stylesheet" th:href="@{../static/layui/css/xadmin.css}">
    <script th:src="@{../static/layui/js/jquery.min.js}"></script>
    <script th:src="@{../static/js/CommonUtil.js}"></script>
    <script th:src="@{../static/js/kconfig.js}"></script>
    <script th:src="@{../static/layui/js/md5.js}" charset="utf-8"></script>
    <script th:src="@{../static/layui/lib/layui/layui.js}" charset="utf-8"></script>
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body class="login-bg">
<script language="javascript">
    if (top !== window)
        top.location.href = window.location.href;
</script>
<div class="login layui-anim layui-anim-up">
    <div class="message"><span th:text="${platformName}"></span>任务调度平台登录</div>
    <div id="darkbannerwrap"></div>
    <form method="post" class="layui-form">
        <input name="username" placeholder="用户名" type="text" class="layui-input">
        <hr class="hr15">
        <input name="password" placeholder="密码" type="password" class="layui-input">
        <hr class="hr15">
        <div class="layui-form-item">
            <input type="text" name="verifyCode" placeholder="验证码" autocomplete="off"
                   class="layui-input verification captcha" value="">
            <div class="captcha-img">
                <a href="javascript:;"><img id="verifyCode" src="/login/getVerifyCode"
                                            onclick="changeCaptcha($(this));"></a>
            </div>
        </div>
        <input value="登录" lay-submit lay-filter="login" style="width:100%;" type="submit">
        <hr class="hr20">
    </form>
</div>

<script>
    function changeCaptcha(obj) {
        obj.attr("src", "/login/getVerifyCode?d=" + new Date().getTime());
    }

    $(function () {
        layui.use('form', function () {
            const form = layui.form;
            //监听提交
            form.on('submit(login)', function (data) {
                const tData = data.field;
                if (tData.username === '') {
                    layer.msg('用户名不能为空');
                    return false;
                }
                if (tData.password === '') {
                    layer.msg('密码不能为空');
                    return false;
                }
                if (tData.verifyCode === '') {
                    layer.msg('验证码不能为空');
                    return false;
                }
                const md5Password = hex_md5(tData.password);
                const jsonParam = JSON.stringify({
                    username: tData.username,
                    password: md5Password,
                    verifyCode: tData.verifyCode
                });
                //请求登入接口
                AjaxRequest.aPost(api.login_in, jsonParam, function (r) {
                    if (r.code === 0) {
                        // 登入成功的提示与跳转
                        layer.msg('登录成功', {
                            offset: '15px', icon: 1, time: 500
                        }, function () {
                            location.href = api.homeView;
                        });
                    } else {
                        if (r.msg !== null && r.msg !== '') {
                            ResponseMsg.errorMsg('登录失败，' + r.msg);
                        } else {
                            ResponseMsg.errorMsg('登录失败，请重试。');
                        }
                    }
                });
                return false;
            });
        });
    })
</script>
</body>
</html>